window.addEventListener('workEvent', function(event) {
	var detail = event.detail;
	setTimeout(function() {
		loadData();

	}, 500)

});



var mask = null;
var login_user = null
$(function() { // 初始化内容
	mui.plusReady();
	mask = mui.createMask(); //遮罩层
	login_user = JSON.parse(localStorage.getItem('loginUser'));
	mui.init();
	datetime_init();
	setTimeout(function() {
		loadData();
	}, 300)

})




function loadData() {
	
	loadkh();
	loadOldClient();
	loadResourceList();
}

function openClientList() {
	window.location.href = "clientList.html"
}
function openOldClientList() {
	window.location.href = "oldClientList.html"
}
function openResourceList(){
	window.location.href = "resourceList.html"
}


function loadkh() {
	var data = {};
	data['page'] = 1;
	data["rows"] = 20;
	data['sort'] = "id"
	console.log("客户数量=====" + JSON.stringify(data));
	jQuery.ajax({
		type: "post",
		headers: {
			'Authorization': login_user.token
		},
		url: serverip + "kf/khGird",
		contentType: 'application/json;charset=UTF-8',
		data: JSON.stringify(data),
		dataType: "json",
		timeout: 10000,
		beforeSend: function() {

			mask.show(); //显示遮罩层	
		},
		success: function(res) {
			
			mask.close(); //显示遮罩层 	  
			console.log("客户数量" + JSON.stringify(res));
			var records = res.records;
			jQuery("#s1").text(records);
		},
		error: function(e) {

			mask.close(); //显示遮罩层
			mui.alert('系统错误');
			console.log("错误信息====" + JSON.stringify(e));
		}
	});
}
function loadOldClient() {
	var data = {};
	data['page'] = 1;
	data["rows"] = 20;
	data['sort'] = "id"
	data["kfyyperson"] = login_user.id;
	console.log("历史客户数量=====" + JSON.stringify(data));
	jQuery.ajax({
		type: "post",
		headers: {
			'Authorization': login_user.token
		},
		url: serverip + "kf/hiskhGrid",
		contentType: 'application/json;charset=UTF-8',
		data: JSON.stringify(data),
		dataType: "json",
		timeout: 10000,
		beforeSend: function() {
	
			mask.show(); //显示遮罩层	
		},
		success: function(res) {
			
			mask.close(); //显示遮罩层 	  
			console.log("学员数量" + JSON.stringify(res));
			var records = res.records;
			jQuery("#s2").text(records);
		},
		error: function(e) {

			mask.close(); //显示遮罩层
			mui.alert('系统错误');
			console.log("错误信息====" + JSON.stringify(e));
		}
	});
}

function loadResourceList() {
	var data = {};
	data['page'] = 1;
	data["rows"] = 20;
	data['sort'] = "id"

	console.log("资源数量=====" + JSON.stringify(data));
	jQuery.ajax({
		type: "post",
		headers: {
			'Authorization': login_user.token
		},
		url: serverip + "kfzg/zyxxGrid",
		contentType: 'application/json;charset=UTF-8',
		data: JSON.stringify(data),
		dataType: "json",
		timeout: 10000,
		beforeSend: function() {
	
			mask.show(); //显示遮罩层	
		},
		success: function(res) {
			
			mask.close(); //显示遮罩层 	  
			console.log("学员数量" + JSON.stringify(res));
			var records = res.records;
			jQuery("#s3").text(records);
		},
		error: function(e) {

			mask.close(); //显示遮罩层
			mui.alert('系统错误');
			console.log("错误信息====" + JSON.stringify(e));
		}
	});
}
